package com.ruoyi.web.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.domain.RechargeRecord;
import com.ruoyi.web.mapper.RechargeRecordMapper;
import com.ruoyi.web.service.IRechargeRecordService;
import com.ruoyi.web.vo.UserRewardRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 充值记录Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-30
 */
@Service
public class RechargeRecordServiceImpl implements IRechargeRecordService {
    @Autowired
    private RechargeRecordMapper rechargeRecordMapper;

    @Override
    public List<RechargeRecord> getUserRecord() {
        startPage();
        Long userId = SecurityUtils.getUserId();
        return rechargeRecordMapper.selectRechargeRecordList(new RechargeRecord() {{
            setUserId(userId);
        }});
    }

    @Override
    public List<RechargeRecord> getUserRewardRecord() {
        startPage();
        Long userId = SecurityUtils.getUserId();
        return rechargeRecordMapper.selectRewardRecordList(new RechargeRecord() {{
            setUserId(userId);
        }});
    }

    @Override
    public List<UserRewardRecordVO> getUserProfitRecord() {
        return null;
    }

    /**
     * 查询充值记录
     *
     * @param id 充值记录主键
     * @return 充值记录
     */
    @Override
    public RechargeRecord selectRechargeRecordById(Long id) {
        return rechargeRecordMapper.selectRechargeRecordById(id);
    }

    /**
     * 查询充值记录列表
     *
     * @param rechargeRecord 充值记录
     * @return 充值记录
     */
    @Override
    public List<RechargeRecord> selectRechargeRecordList(RechargeRecord rechargeRecord) {
        return rechargeRecordMapper.selectRechargeRecordList(rechargeRecord);
    }

    /**
     * 新增充值记录
     *
     * @param rechargeRecord 充值记录
     * @return 结果
     */
    @Override
    public int insertRechargeRecord(RechargeRecord rechargeRecord) {
        rechargeRecord.setCreateTime(DateUtils.getNowDate());
        return rechargeRecordMapper.insertRechargeRecord(rechargeRecord);
    }

    /**
     * 修改充值记录
     *
     * @param rechargeRecord 充值记录
     * @return 结果
     */
    @Override
    public int updateRechargeRecord(RechargeRecord rechargeRecord) {
        rechargeRecord.setUpdateTime(DateUtils.getNowDate());
        return rechargeRecordMapper.updateRechargeRecord(rechargeRecord);
    }

    /**
     * 批量删除充值记录
     *
     * @param ids 需要删除的充值记录主键
     * @return 结果
     */
    @Override
    public int deleteRechargeRecordByIds(Long[] ids) {
        return rechargeRecordMapper.deleteRechargeRecordByIds(ids);
    }

    /**
     * 删除充值记录信息
     *
     * @param id 充值记录主键
     * @return 结果
     */
    @Override
    public int deleteRechargeRecordById(Long id) {
        return rechargeRecordMapper.deleteRechargeRecordById(id);
    }
}
